<template>
<div class="hd transfer  mt20">
    <el-card class="box-card" v-if="depts.length > 0">
      <div slot="header" class="clearfix">
        <span>推荐科室</span>
      </div>
      <div v-for="dept in depts" :key="dept.id" class="text item">
         <span @click="goDoctorPage(dept)">{{dept.deptName}}</span>
      </div>
    </el-card>
    <div class="no-data" v-else>
        暂无数据
        <p>
          <router-link to="/yygh">手动查找</router-link>
        </p>
    </div>
</div>
</template>

<script>
import {commonAjax, PLATFORM_PREFIX} from '../../api/api'

export default {
  data () {
    return {
      depts: []
    }
  },
  mounted () {
    if (!this.$route.query.deptId) {
      return
    }
    this.$store.commit('UPDATE_LOADING')
    commonAjax([this.$route.query.deptId], `${PLATFORM_PREFIX}.deptContrastService`, 'getDeptContrastById').then(res => {
      this.$store.commit('UPDATE_LOADING')
      if (res.data.code === 200) {
        if (res.data.body.length === 1) {
          // 只有一个科室匹配
          this.goDoctorPage(res.data.body[0])
        } else {
        // 多个科室匹配
          this.depts = res.data.body
        }
      } else {
        this.$store.commit('UPDATE_TOAST', {message: res.data.msg})
      }
    }).catch(res => {
      this.$store.commit('UPDATE_LOADING')
      this.$store.commit('UPDATE_TOAST', {
        message: '请先登录',
        fn: () => this.$router.push('/login?redirect=' + this.$route.fullPath)
      })
    })
  },
  methods: {
    goDoctorPage (dept) {
      localStorage.dept = JSON.stringify(dept)
      this.$router.replace({
        path: '/yygh',
        query: {
          localDeptId: dept.localDeptId,
          deptId: dept.deptId
        }
      })
    }
  }
}
</script>

<style lang="less">
.transfer {
  .box-card {
    min-height: 400px;
  }
  .text {
    padding: 10px 20px;
    border: 1px solid #eee;
    margin-top: -1px;
    cursor: pointer;
    float: left;
    margin-right:20px; 
    &:hover {
      color:#fff;
      background: #9E310F;
    }
  }
}
</style>
